﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HWmanagementClient.HWManager;
using System.Security.Principal;
using HWmanagementClient.Models;

namespace HWmanagementClient.Codes
{
    public static class Site
    {
        public static int GetAuthUserRank(HttpRequestBase req, IPrincipal user)
        {
            UserModel loggedin = new UserModel();
            if (req.IsAuthenticated)
            {
                try
                {
                    loggedin = loggedin.GetLoggedinUser(user.Identity.Name);
                }
                catch (Exception e)
                {
                    throw e;
                }
                return loggedin.Rank;
            }
            else
            {
                return -1;
            }
        }

        public static string GetAuthUserCode(HttpRequestBase req, IPrincipal user)
        {
            UserModel loggedin = new UserModel();
            if (req.IsAuthenticated)
            {
                try
                {
                    loggedin = loggedin.GetLoggedinUser(user.Identity.Name);
                }
                catch (Exception e)
                {
                    throw e;
                }
                return loggedin.Neptun;
            }
            else
            {
                return "";
            }
        }

        public static string GetAuthUserMail(HttpRequestBase req, IPrincipal user)
        {
            UserModel loggedin = new UserModel();
            if (req.IsAuthenticated)
            {
                try
                {
                    loggedin = loggedin.GetLoggedinUser(user.Identity.Name);
                }
                catch (Exception e)
                {
                    throw e;
                }
                return loggedin.Email;
            }
            else
            {
                return "";
            }
        }

        public static Tuple<string, string, string> GetAuthUserData(HttpRequestBase req, IPrincipal user)
        {
            UserModel loggedin = new UserModel();
            if (req.IsAuthenticated)
            {
                try
                {
                    loggedin = loggedin.GetLoggedinUser(user.Identity.Name);
                }
                catch (Exception e)
                {
                    throw e;
                }
                return new Tuple<string, string, string>(loggedin.Name, loggedin.Neptun, loggedin.Email);
            }
            else
            {
                return new Tuple<string, string, string>("", "", "");
            }
        }
    
    }
}